package com.zhkj.lib.utils

import android.os.Handler
import android.os.Looper
import android.widget.Toast
import com.zhkj.lib.base.BaseApplication

object ToastUtil {

    private var toast: Toast? = null
    private var handler: Handler = Handler(Looper.getMainLooper())

    fun show(content: String) {
        if (toast == null) {
            toast = Toast.makeText(BaseApplication.INSTANCE, content, Toast.LENGTH_SHORT)
        } else {
            toast?.setText(content)
            toast?.duration = Toast.LENGTH_SHORT
        }
        showToast()
    }

    private fun showToast() {
        if (Looper.myLooper() == Looper.getMainLooper()) toast?.show()
        else handler.post { toast?.show() }
    }
}